/*
 * @Author       : wfl
 * @LastEditors: qiye
 * @description  :
 * @updateInfo   :
 * @Date         : 2023-02-28 11:45:50
 * @LastEditTime: 2023-12-14 18:32:12
 */
import { ikTree } from 'iking-utils'
import { ikHttp, textHeader } from '@g/api/request'

export const depApi = {
  getAllDeps: async (params?: any) => {
    return await ikHttp.post('/server/system/dept/list/all', params, {
      headers: {
        'Content-Type': 'application/json;charset=UTF-8'
      }
    })
  },
  // 获取部门树型列表
  getDepTree: async () => ikTree.listToTree((await depApi.getAllDeps())?.data || []),
  // 新增部门
  addDep: async (params: any) => await ikHttp.post('/server/system/dept/add', params),
  // 修改
  updateDep: async (params: any) => await ikHttp.post('/server/system/dept/update', params),
  // 删除
  deleteDep: async (deptId: string) => await ikHttp.post('/server/system/dept/delete', deptId, textHeader),
  // 排序
  sortTree: async (params: any) => await ikHttp.post('/server/system/dept/drag', params),
  // 获取子单位
  getChildDep: async (parentId: string, includeSelf = false) => await ikHttp.post(`/server/system/dept/sub/list/all/parent-id?includeSelf=${includeSelf}`, parentId, textHeader),
  getChildDepV2: async (params: any) => await ikHttp.post('/server/system/dept/sub/all/list', params)

}
